fix(p2p): update peer address on reconnect and optimize reacher#5348
Merged
gacevicljubisa merged 6 commits intomasterfrom Feb 13, 2026
Merged
fix(p2p): update peer address on reconnect and optimize reacher#5348gacevicljubisa merged 6 commits intomasterfrom
gacevicljubisa merged 6 commits intomasterfrom
Conversation
akrem-chabchoub
approved these changes
Feb 10, 2026
martinconic
reviewed
Feb 13, 2026
| } | ||
|
|
||
| // peerHeap is a min-heap of peers ordered by retryAfter time. | ||
| type peerHeap []*peer |
Contributor
There was a problem hiding this comment.
I would move the heap into a separate file
| defer r.wg.Done() | ||
|
|
||
| c := make(chan *peer) | ||
| c := make(chan peer) |
Contributor
There was a problem hiding this comment.
Here and also bellow, why not using a pointer to a peer anymore?
Member
Author
There was a problem hiding this comment.
By sending a value copy through the channel, each ping goroutine gets its own independent snapshot of the peer data, which is safe to read concurrently
janos
approved these changes
Feb 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
Description
This PR improves the reacher component in two ways:
1. Optimize peer scheduling with a min-heap
Replace the
map[string]*peerwith a min-heap ordered byretryAftertime,backed by an index map for O(1) lookups. The previous implementation iterated
over all peers on every scheduling cycle to find the one with the earliest
retry time. The heap reduces this to O(1) peek / O(log n) updates.
2. Update peer underlay address on reconnect
When a peer reconnects (same overlay, different underlay), the reacher now
updates the stored multiaddr and resets the retry timer to trigger an
immediate re-ping. Previously, duplicate
Connectedcalls for the sameoverlay were silently ignored, causing the reacher to keep pinging the
stale address. This is particularly important for peers that support
multiple underlays or change IP addresses between connections.
After the immediate re-ping, the next scheduled ping follows the normal
RetryAfterDurationcadence.Open API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
Screenshots (if appropriate):